<include file='public/_meta'>
<title>车辆列表</title>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 车辆档案 <span class="c-gray en">&gt;</span> 车辆列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
            <div class="text-c" id="search_down"> 添加日期：
                <input type="text" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'datemax\')||\'%y-%M-%d\' }' })" id="datemin" class="input-text Wdate" style="width:100px;">
                -
                <input type="text" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'datemin\') }',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:100px;">
                <input type="text" class="input-text" style="width:250px" placeholder="车牌、车架、卡号、智能设备号..." id="search_inpute" >
                <span class="select-box" style="width:100px;">
                    <select class="select" id="brand_id">
                        <option value="" style="color: #429842;">品牌类型</option>
                        <foreach $brand as $value>
                        <option value="{$value.id}">{$value.name}</option>
                        </foreach>                        
                    </select>
                </span>
                <span class="select-box" style="width:96px;">
                    <select class="select" name="relevance" id="relevance" size="1">
                        <option value="" style="color: #429842;">租赁类型</option>
                        <option value="1">分时租赁</option>
                        <option value="2">企业用车</option>
                        <option value="3">共享用车</option>
                        <option value="4">长租车辆</option>
                        <option value="5">自测试用</option>
                        <option value="6">上牌整备</option>
                        <option value="7">整备待租</option>
                    </select>
                </span>
                <span class="select-box" style="width:100px;">
                    <select class="select" id="agency_id">
                        <option value="" style="color: #429842;">加盟商</option>
                        <foreach $agency as $value>
                        <option value="{$value.id}">{$value.name}</option>
                        </foreach>
                        
                    </select>
                </span>
                <span class="select-box" style="width:96px;">
                    <select class="select" name="supplier_no" id="supplier_no" size="1">
                        <option value="" style="color: #429842;">车机型号</option>
                        <option value="1376920001">W</option>
                         <option value="1376920003">S-IOT</option>
                        <option value="1376920002">S</option>
                    </select>
                </span>
                <span class="select-box" style="width:96px;">
                    <select class="select" name="sim_card" id="sim_card" size="1">
                        <option value="" style="color: #429842;">SIM卡商</option>
                        <option value="1376920004">阿里云</option>
                        <option value="1376920005">赛卡</option>
                    </select>
                </span>
                <button type="submit" class="btn btn-success radius" id="search_btn"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>       
            </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" onclick="product_add('添加车辆','{:url('index/cars/add')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加车辆</a></span>  <span class="ml-5"> <a class="btn btn-success radius" onclick="excel_data_add('excel导入','{:url('index/cars/excelToData')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> EXCEL导入</a></span> <span class="ml-5"> <a class="btn btn-warning radius" onclick="excel_data_out('导出excel','{:url('index/excell/cars')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe641;</i> 导出EXCEL</a></span> <span class="r">共有数据：<strong>{$number}</strong> 条</span> </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort">
            <thead>
                <tr class="text-c">
                
                    <th width="40">ID</th>
                    <th width="">车牌号</th>
                    <th width="">品牌名称</th>
                    <th width="">车架号</th>
                    <th width="">租赁类型</th>
                    <th>加盟商</th>
                    <th>车机型号</th>
                    <th>SIM卡商</th>
                    <th>小电瓶</th>
                    <th width="40">状态</th>
                    <th width="120">车机时间</th>
                    <th width="120">添加时间</th>
                    <!-- <th width="60">发布状态</th> -->
                    <th width="100">操作</th>
                </tr>
            </thead>
            <tbody>
                
            </tbody>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){
    var table = $('.table-sort').DataTable({
        "aaSorting": [[ 0, "desc" ]],//默认第几个排序
        // "bStateSave": true,//状态保存
         searching: false,
        "aoColumnDefs": [
          //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
          {"orderable":false,"aTargets":[0,1,2,3,4,5,6,7,8]}// 制定列不参与排序
        ],
        "bProcessing" : true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好  
        "bServerSide" : true,//服务器处理分页，默认是false，需要服务器处理，必须true  
        "ajax": {
            "url": "{:url('index/Cars/index')}",
            "type": "POST"
        },
        displayLength: 10,
        columns: [
        { data: 'car_id' },
        { render:function (data, type, row, meta) {
                let str = '<u style="cursor:pointer" class="text-primary" onClick="';
                    str += "cars_details('详情','{:url('details')}','";
                    str += row['car_id'];
                    str += "','',450)";
                    str += '" title="详情">';
                    str += row['car_sn'];
                    str += '</u>'; 
                return str;
        }
        },
        { data: 'brand_name' },
        { data: 'car_unique_id' },
        { data: 'relevance' ,render:function(data, type, row, meta){
            switch (data) {
                case 1:
                data = '分时租赁';     
                    break;
                case 2:
                data = '企业用车';     
                    break;
                case 3:
                data = '共享用车';     
                    break;
                case 4:
                data = '长租车辆';     
                    break;
                case 5:
                data = '自测试用';     
                    break;
                case 6:
                data = '上牌整备';     
                    break;
                case 7:
                data = '整备待租';     
                    break;    
                default:
                data = '暂无分类';   
                    break;
            }
            return data;

        }},
        { data: 'agency_name'},
        { data:'supplier_no',render:data=>{
                switch (data) {
                    case '1376920002':
                    data = 'S';     
                        break;
                    case '1376920001':
                    data = 'W';     
                        break;
                        case '1376920003':
                    data = 'S-IOT';     
                        break;
                    default:
                    data = '未知';   
                        break;
                }
               
                return data;
            } 
        },
        { data:'sim_card',render:data=>{
                switch (data) {
                    case '1376920004':
                    data = '阿里云';     
                        break;
                    case '1376920005':
                    data = '赛卡';     
                        break;
                    default:
                    data = '未知';   
                        break;
                }
               
                return data;
            } 
        },
        { render:function (data, type, row, meta) {
                if(row.cars_info){
                    data = row.cars_info.voltage!==null?row.cars_info.voltage+'V':'暂无数据';
                }else{
                    data = '未知';
                }
                return data;
            } 
        },
        { render:function (data, type, row, meta) {

                if(row.cars_info){
                    if(row.cars_info.network_status == 0){
                        return '<span class="label radius">离线</span>';
                    }else if(row.cars_info.network_status == 1){
                        return '<span class="label label-success radius">在线</span>';
                    }else{
                        return '未知';
                    }
                    
                }else{
                    return '未知';
                }
                
            } 
        },
        { render:function (data, type, row, meta) {
                if(row.cars_info){
                    if(row.cars_info.machine_report_time!=null && row.cars_info.machine_report_time!=0){
                        let formatTimeS = new Date(row.cars_info.machine_report_time);
                        let _year = formatTimeS.getFullYear()
                        let _month = formatTimeS.getMonth()+1;
                        let _date = formatTimeS.getDate();
                        let _hour = formatTimeS.getHours();
                        let _minute = formatTimeS.getMinutes();
                        let _second = formatTimeS.getSeconds();
                        return _year+'-'+_month+'-'+_date+' '+_hour+':'+_minute+':'+_second;
                        
                    }else{
                       data = '未知'; 
                    }
                }else{
                    data = '未知';
                }
                return data;
            } 
        },
        { data: 'create_time' },
        { className: "td-manage",data: '',render: function (data, type, row, meta) {
                                    var str = '';
                                    if(row['band_status']==0){
                                        str += '<a title="绑定车辆" href="javascript:;" onclick="product_start(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe603;</i></a>';
                                    }else if(row['band_status']==1){
                                        str += '<a title="解除绑定" href="javascript:;" onclick="product_stop(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6de;</i></a>';
                                        
                                    }

                                    str += '<a title="编辑" href="javascript:;" onclick="product_edit(this,';
                                    str += "'编辑',";
                                    str += "'{:url('index/Cars/edit')}?car_id="+row['car_id']+"'";
                                    str += ",'',550)\"";
                                    str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
                                    str += '<a title="删除" href="javascript:;" onclick="product_del(this,'+row['car_id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                                    if(row['supplier_no'] == 1376920002 || row['supplier_no'] == 1376920003){
                                        str += '<a title="车辆控制" href="javascript:;" onclick="operate(';
                                        str += "'车辆控制',";
                                        str += "'{:url('index/operate/index')}?id="+row['car_id']+"'";
                                        str += ",'',450)\"";
                                        str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>';
                                    }
                                    if(row['supplier_no'] == 1376920003 || row['supplier_no'] == 1376920002){
                                        str += '<a title="历史数据" href="javascript:;" onclick="historical_data(';
                                        str += "'历史数据',";
                                        str += "'{:url('index/Cars/previous')}?car_unique_id="+row['car_unique_id']+"&supplier_no="+row['supplier_no']+"'";
                                        str += ",'',550)\"";
                                        str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe681;</i></a>';
                                    }
                                    if(row['supplier_no'] == 1376920002 || row['supplier_no'] == 1376920003){
                                        str += '<a title="车型切换" href="javascript:;" onclick="type_switch(';
                                        str += "'车型切换',";
                                        str += "'{:url('index/operate/switch')}?car_unique_id="+row['car_unique_id']+"'";
                                        str += ",'',450)\"";
                                        str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6f1;</i></a>';
                                    }
                                return str;
                                
                            }
        },

        ],
         
    });

    $("#search_btn").click(res=>{
        request();
    });

    $("#search_down").keydown(event=>{
           if (event.which == 13){
                request();
           }
    })

    function request() {
        table.settings()[0].ajax.data = {
            'datemin':$('#datemin').val(),
            'datemax':$('#datemax').val(),
            'brand_id':$('#brand_id').val(),
            'relevance':$('#relevance').val(),
            'agency_id':$('#agency_id').val(),
            'supplier_no':$('#supplier_no').val(),
            'sim_card':$('#sim_card').val(),
            'search_inpute':$('#search_inpute').val(),
        };
        table.ajax.reload();
    }

});

function operate(title,url,w,h) {
    layer_show(title,url,w,h);
}

function type_switch(title,url,w,h){
    layer_show(title,url,w,h);
}

function cars_details(title,url,id,w,h) {
    layer_show(title,url+'?id='+id,w,h);
}
/*导入表格数据*/
function excel_data_add(title,url,w,h){
    layer_show(title,url,w,h);
}
/*导出*/
function excel_data_out(title,url,w,h) {
    layer.confirm('<p class="c-warning">可以选择搜索条件导出</p>',function(index){
        // top.location.href = url;
        let datemin = $('#datemin').val();
        let datemax = $('#datemax').val();
        let brand_id = $('#brand_id').val();
        let relevance = $('#relevance').val();
        let agency_id = $('#agency_id').val();
        let supplier_no = $('#supplier_no').val();
        let sim_card = $('#sim_card').val();
        let search_inpute = $('#search_inpute').val();

        window.location.href = url+'?'+'datemin='+datemin+'&datemax='+datemax+'&brand_id='+brand_id+'&relevance='+relevance+'&agency_id='+agency_id+'&supplier_no='+supplier_no+'&sim_card='+sim_card+'&search_inpute='+search_inpute;

            layer.msg('导出成功,正在下载', {icon: 1});
            
    
    });

}
/*产品-添加*/
function product_add(title,url){
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
/*产品-查看*/
function product_show(title,url,id){
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
/*产品-审核*/
function product_shenhe(obj,id){
    layer.confirm('审核文章？', {
        btn: ['通过','不通过'], 
        shade: false
    },
    function(){
        $(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
        $(obj).remove();
        layer.msg('已发布', {icon:6,time:1000});
    },
    function(){
        $(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
        $(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
        $(obj).remove();
        layer.msg('未通过', {icon:5,time:1000});
    }); 
}
/*车辆解绑*/
function product_stop(obj,id){
    layer.confirm('解除绑定',function(index){
        $.ajax({
            type: 'POST',
            url: '{:url('index/Cars/unBandCars')}',
            data:{'id':id},
            dataType: 'json',
            success: function(data){
                if(data.result == 0){

                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_start(this,'+id+')" href="javascript:;" title="绑定车辆"><i class="Hui-iconfont">&#xe603;</i></a>');
                    $(obj).remove();
                    layer.msg('已解绑!',{icon: 5,time:1000});
                }else{
                    layer.msg(data['msg']);
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        }); 
        
        
    });
}

/*车辆绑定*/
function product_start(obj,id){
    layer.confirm('绑定车辆',function(index){
        $.ajax({
            type: 'POST',
            url: '{:url('index/Cars/bandCars')}',
            data:{'id':id},
            dataType: 'json',
            success: function(data){
                if(data.result == 0){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_stop(this,'+id+')" href="javascript:;" title="解除绑定"><i class="Hui-iconfont">&#xe6de;</i></a>');
                    $(obj).remove();
                    layer.msg('已绑定!',{icon: 6,time:1000});
                }else{
                    layer.msg(data['msg']);
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });

        
    });
}

/*产品-申请上线*/
function product_shenqing(obj,id){
    $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
    $(obj).parents("tr").find(".td-manage").html("");
    layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}

/*产品-编辑*/
function product_edit(obj,title,url){
    var str = $(obj).parents("tr").find(".td-manage").html();
    if(str.indexOf("绑定车辆") == -1){
        layer.msg('请先解除绑定');
    }else{
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
        
    }
}

/*产品-删除*/
function product_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: "{:url('index/Cars/delete')}",
            data:{'id':id},
            dataType: 'json',
            success: function(data){
                if(data.code == 0){

                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                }else{
                    layer.msg(data['msg']);
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });     
    });
}


/*查看历史数据*/
function historical_data(title,url){
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
</script>
</body>
</html>